﻿@using FineAdmin.Model;
@{
    ViewBag.Title = "友情链接";
    var FriendlyList = ViewBag.FriendlyList as List<FriendlyModel>;
    FriendlyList = FriendlyList.Where(m => m.State == 1).ToList();
}
@section styles{
    <style>
        .site-block {
            padding: 20px;
            border: 1px solid #eee;
        }
    </style>
}

<div class="content w1000">
    <div class="layui-row layui-col-space10">
        @foreach (var item in FriendlyList)
        {
            <div class="layui-col-xs6 layui-col-sm3 layui-col-md3">
                <div class="layui-card">
                    <a href="@(string.IsNullOrWhiteSpace(item.Href)?item.DomainName:item.Href)" target="_blank">
                        <div class="layui-card-header layui-bg-red">@item.Name</div>
                        <div class="layui-card-body">
                            @item.Introduce
                        </div>
                    </a>
                </div>
            </div>
        }
        <div class="layui-col-xs6 layui-col-sm3 layui-col-md3">
            <div class="layui-card " id="add">
                <div class="layui-card-header layui-bg-green">点此申请友链 <i class="layui-icon layui-icon-face-smile"></i></div>
                <div class="layui-card-body">
                    提交友链后，请加站长微信申请上墙(备注友情链接)。
                </div>
            </div>
        </div>
    </div>
</div>

<div id="addDiv" style="display:none;" class="layui-form">
    <div class="site-text site-block">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">网站名称</label>
                <div class="layui-input-block">
                    <input type="text" name="Name" required="" lay-verify="required" placeholder="请输入网站名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">网站域名</label>
                <div class="layui-input-block">
                    <input type="text" name="DomainName" required="" lay-verify="required" placeholder="请输入网站域名" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">指向页面</label>
                <div class="layui-input-block">
                    <input type="text" name="Href" placeholder="请输入指向页面，不填写则指向域名" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">网站介绍</label>
                <div class="layui-input-block">
                    <textarea name="Introduce" placeholder="请输入网站介绍" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">微信/手机</label>
                <div class="layui-input-block">
                    <input type="text" name="Phone" placeholder="请输入微信或者手机号" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-block">
                    <input type="text" name="Mail" placeholder="请输入邮箱，接受通知" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <img src="/Friendly/GetSubmitCode" onclick="getcode()" id="codeimg" />
                </div>
                <div class="layui-input-block">
                    <input type="text" name="captcha" placeholder="请输入验证码" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">

                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="add">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>

        </form>
    </div>
</div>

@section scripts{
    <script>
        function getcode() {
            //$("#code").src = '/mobile/GetSubmitCode?' + Math.random()
            document.getElementById("codeimg").src = "/Friendly/GetSubmitCode?r=" + Math.random();
        }
        


        layui.config({
            base: '../BlogStatic/js/util/'
        }).use(['element', 'laypage', 'form', 'menu', 'jquery'], function () {
            element = layui.element, laypage = layui.laypage, form = layui.form, menu = layui.menu,$ = layui.$;
            $("#add").click(function () {
                layer.open({
                    type: 1
                    , area: '98%'
                    , content: $('#addDiv')
                });
            });

            form.on("submit(add)", function (data) {

                $.ajax({
                    url: "/Friendly/Add",
                    data: data.field,
                    type: "Post",
                    dataType: "json",
                    success: function (data) {

                        layer.msg(data.message);
                        document.getElementById("codeimg").src = "/Friendly/GetSubmitCode?r=" + Math.random();

                    },
                    error: function (data) {

                        layer.msg(data.message);
                    }
                });

                return false;
            });

            menu.init();
        })
    </script>
}